<template>
  <div
    class="canvas-attr-container"
    :style="{
      color: themeStyle[theme].textColor1
    }"
  >
    <!-- 画布属性标题 -->
    <div
      class="title"
      :style="{
        borderBottom: `1px solid ${themeStyle[theme].borderColor1}`
      }"
    >
      <span style="color: #0087dc">{{ '画布属性' }}</span>
      <div class="icon" :class="canvasData.lock ? 'lockIcon' : ''">
        <template v-if="canvasData.lock">
          <LockOutlined @click="switchLock" />
        </template>
        <template v-else>
          <UnlockOutlined @click="switchLock" />
        </template>
      </div>
    </div>

    <!-- 画布属性主体内容 -->
    <div class="attr-content">
      <SizeTransition>
        <Form
          :model="canvasData"
          :label-col="{ span: 8 }"
          :wrapper-col="{ span: 16 }"
          :label-align="'left'"
          :disabled="canvasData.lock"
          autocomplete="off"
        >
          <FormItem name="canvasBackground">
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '画布背景' }}</span
              >
            </template>
            <div style="display: flex">
              <ColorSelect
                v-model:color="canvasData.background"
                :disable="canvasData.lock"
                :height="24"
                @change="handleChange"
              />
            </div>
          </FormItem>

          <!-- 启用网格和网格颜色 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '启用网格' }}</span
              >
            </template>
            <Switch
              v-model:checked="canvasData.showGrid"
              size="small"
              checked-children="开"
              un-checked-children="关"
              @change="handleChange"
            />
          </FormItem>
          <FormItem v-if="canvasData.showGrid">
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '网格颜色' }}</span
              >
            </template>
            <div style="display: flex">
              <ColorSelect
                v-model:color="canvasData.gridColor"
                :disable="canvasData.lock"
                :height="24"
                @change="handleChange"
              />
            </div>
          </FormItem>

          <!-- 选中样式 -->
          <FormItem name="selectedNodeStyle">
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '选中样式' }}</span
              >
            </template>
            <Select
              v-model:value="canvasData.selectedNodeStyle"
              size="small"
              @change="handleChange"
            >
              <SelectOption value="rotate">
                <span style="color: #666; font-size: 14px">旋转线条</span>
              </SelectOption>
              <SelectOption value="ripple">
                <span style="color: #666; font-size: 14px">水纹涟漪</span>
              </SelectOption>
              <SelectOption value="mask">
                <span style="color: #666; font-size: 14px">阴影遮罩</span>
              </SelectOption>
            </Select>
          </FormItem>

          <!-- 样式颜色 -->
          <FormItem name="canvasBackground">
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '样式颜色' }}</span
              >
            </template>
            <div style="display: flex">
              <ColorSelect
                v-model:color="canvasData.selectedNodeStyleColor"
                :disable="canvasData.lock"
                :height="24"
                @change="handleChange"
              />
            </div>
          </FormItem>

          <!-- 启用对齐线 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '启用对齐' }}</span
              >
            </template>
            <Switch
              v-model:checked="canvasData.enableSnapline"
              size="small"
              checked-children="开"
              un-checked-children="关"
              @change="handleChange"
            />
          </FormItem>
        </Form>

        <div class="shortcut-keys">
          <div
            class="shortcut-keys-title"
            :style="{
              backgroundColor: themeStyle[theme].backgroundColor3
            }"
          >
            <!-- <RightOutlined style="transform: rotate(90deg)" /> -->
            <span style="margin-left: 5px">快捷键提示</span>
          </div>
          <div
            class="shortcut-keys-content"
            :style="{ color: themeStyle[theme].textColor1 + 'aa' }"
          >
            <template v-for="(item, index) in shortcutKeys" :key="index">
              <div class="shortcut-keys-item">
                <span>{{ item.key }}</span>
                <span>{{ item.describe }}</span>
              </div>
            </template>
          </div>
        </div>
      </SizeTransition>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onUnmounted, ref } from 'vue'
import { Form, FormItem, Select, SelectOption, Switch } from 'ant-design-vue'
import { useStyleStore } from '@renderer/store/globalStyle/style'
import { storeToRefs } from 'pinia'
import SizeTransition from '@renderer/components/sizeTransition/SizeTransition.vue'
import { LockOutlined, UnlockOutlined, RightOutlined } from '@ant-design/icons-vue'
import ColorSelect from '@renderer/components/colorSelect/ColorSelect.vue'

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
    required: false
  }
})

//属性数据
const canvasData = ref(props.data)

onUnmounted(() => {
  handleChange()
})

const handleChange = (): void => {
  const newData = JSON.parse(JSON.stringify(canvasData.value))
  window.api.handleCanvasData('setCanvasProperties', 'property', true, [newData])
}

const switchLock = (): void => {
  canvasData.value.lock = !canvasData.value.lock
  handleChange()
}

const globalStyleStore = useStyleStore()
const { theme, themeStyle } = storeToRefs(globalStyleStore)

//快捷键
const shortcutKeys = [
  {
    key: '滑轮',
    describe: '缩放画布'
  },
  {
    key: 'Ctrl + 滑轮',
    describe: '纵向移动画布'
  },
  {
    key: 'Shift + 滑轮',
    describe: '横向移动画布'
  },
  {
    key: '空格键',
    describe: '拖拽画布'
  },
  {
    key: 'Delete',
    describe: '删除节点和边'
  },
  {
    key: 'Ctrl + F',
    describe: '显示搜索框'
  },
  {
    key: 'Ctrl + C',
    describe: '复制节点'
  },
  {
    key: 'Ctrl + V',
    describe: '粘贴节点'
  },
  {
    key: 'Ctrl + Z',
    describe: '撤销'
  },
  {
    key: 'Shift + E',
    describe: '显示边端按钮'
  },
  {
    key: 'Shift + R',
    describe: '显示参考线'
  },
  {
    key: 'Shift + F',
    describe: '画布全屏'
  }
]
</script>

<style scoped lang="scss">
.canvas-attr-container {
  width: 100%;
  height: 100%;
  font-size: $font-size-medium;

  .title {
    padding: 3px 5px;

    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;

    .icon {
      margin-right: 10px;
      width: 25px;
      height: 25px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 5px;
      color: #7e7e7e;
      cursor: pointer;
    }
    .lockIcon {
      background-color: $icon-active-bgColor;
      color: $icon-active-color;
    }
  }

  .attr-content {
    padding: 5px 3px 5px 6px;
    height: calc(100% - 60px);

    :deep(.ant-form-item) {
      margin-bottom: 0px;
    }
    :deep(.ant-input-sm) {
      border-radius: 0px;
    }
    :deep(.ant-select-selector) {
      border-radius: 0px;
    }

    .content-item-label {
      font-size: $font-size-medium;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .shortcut-keys {
      margin-top: 10px;
      .shortcut-keys-title {
        padding-left: 5px;
        line-height: 25px;
        height: 25px;
        font-size: $font-size-small;
      }
      .shortcut-keys-content {
        font-size: $font-size-small;
        padding: 0px 5px;
        .shortcut-keys-item {
          margin-top: 5px;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    }
  }
}
</style>
